Skip to content

feat: Generate shell completions on install#3

Open
jalaziz wants to merge 1 commit into
withgraphite:masterfrom
jalaziz:generate-completions
Open

feat: Generate shell completions on install#3
jalaziz wants to merge 1 commit into
withgraphite:masterfrom
jalaziz:generate-completions

Conversation

@jalaziz

@jalaziz jalaziz commented Oct 12, 2022

Copy link
Copy Markdown

Homebrew can automatically generate and install completions for bash,
zsh, and fish. For now, completion is limited to bash and zsh until
graphite adds fish support.

This simplifies the installation steps for homebrew users.

@jalaziz jalaziz force-pushed the generate-completions branch from 31746b5 to 295d3c7 Compare February 9, 2023 04:14
@jalaziz jalaziz force-pushed the generate-completions branch from 295d3c7 to d52c23e Compare June 28, 2023 06:40
@jalaziz

jalaziz commented Jun 28, 2023

Copy link
Copy Markdown
Author

@dbalatero @goldjacobe Sorry to be a pest and ping you directly, but any chance this could be reviewed?

This helps simply the graphite CLI install to a single step.

@jalaziz jalaziz force-pushed the generate-completions branch from d52c23e to b18db02 Compare June 28, 2023 06:56
@jalaziz jalaziz force-pushed the generate-completions branch from b18db02 to 5555c43 Compare July 14, 2023 18:11
@goldjacobe

Copy link
Copy Markdown
Contributor

Thanks for these PRs, I'll integrate soon (we have some other inflight changes to the release process I want to finalize first)

@goldjacobe

Copy link
Copy Markdown
Contributor

this diff doesn't seem to work as expected.

@jalaziz

jalaziz commented Jul 22, 2023

Copy link
Copy Markdown
Author

@goldjacobe What issue are you seeing? No completions installed?

I had run into some issues during the last rebased, but thought I fixed everything.

I'm rebasing to test again.

Homebrew can automatically generate and install completions for bash,
zsh, and fish. For now, completion is limited to bash and zsh until
graphite adds fish support.

This simplifies the installation steps for homebrew users.
@jalaziz jalaziz force-pushed the generate-completions branch from 5555c43 to c880a52 Compare July 22, 2023 23:50
@jalaziz

jalaziz commented Jul 22, 2023

Copy link
Copy Markdown
Author

@goldjacobe I just rebased and tested and it's installing the shell completions for me (I'm using zsh). Are you not seeing completions installed?

For zsh, the shell completions are installed to $(brew --prefix)/share/zsh/site-functions/_graphite. Depending on your setup, you may have to load the completions from Homebrew's completion directory: https://docs.brew.sh/Shell-Completion (not needed if you use brew installed shells)

@sumanthratna

Copy link
Copy Markdown

Following up here since this stalled — I dug into why this diff may not have worked as expected, and opened #30 which supersedes it (full diagnosis and testing evidence there). Credit to @jalaziz for the original approach — the install-time generate_completions_from_executable call was the right idea. Two root causes, both quirks of yargs rather than this diff's structure:

  1. yargs can only emit bash and zsh completion scripts, selected via the SHELL env var that generate_completions_from_executable sets per shell. Requesting :fish made yargs fall back to emitting a bash script into fish's completions directory, so the fish output was broken from the start.

  2. The zsh script yargs emits only registers the completercompdef runs at the end of the file, but nothing invokes the function (Generate zsh autoload completion function file yargs/yargs#2402). As an autoloaded fpath file, the first <Tab> of every shell session therefore completes nothing, and it works from the second attempt onward. I suspect this explains the impasse above: "this diff doesn't seem to work" and "it's installing the completions for me" were both accurate observations.

#30 limits generation to [:bash, :zsh], appends a _gt_yargs_completions "$@" invocation to the installed _gt so the first Tab works, and patches the formula template plus both rendered formulas so the release pipeline won't clobber the change on the next version bump. (It also chmods the binary before invoking it — the downloaded release artifact carries no exec bit during install and fails with EACCES otherwise.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants